<template>
  <div class="app-container">
    <div class="vertical-table">
      <div v-for="(doctor, index) in doctors" :key="index" class="data-block">
        <div class="table-row">
          <div class="table-cell">医生头像</div>
          <div class="table-cell">
            <img :src="doctor.doctorPic" width="35px" height="35px" />
          </div>
        </div>
        <div class="table-row">
          <div class="table-cell">医生姓名</div>
          <div class="table-cell">
            <el-input v-model="doctor.doctorName" disabled/>
          </div>
        </div>
        <div class="table-row">
          <div class="table-cell">医生职位</div>
          <div class="table-cell">
            <el-input v-model="doctor.doctorPositions" disabled/>
          </div>
        </div>
        <div class="table-row">
          <div class="table-cell">所在医院</div>
          <div class="table-cell">
            <el-input v-model="doctor.doctorHospital" disabled/>
          </div>
        </div>
        <div class="table-row">
          <div class="table-cell">所在科室</div>
          <div class="table-cell">
              <dict-tag :options="dict.type.hospital_department" :value="doctor.doctorDepartments" />
          </div>
        </div>
        <div class="table-row">
          <div class="table-cell"></div>
          <div class="table-cell">
            <el-button type="danger" @click="deleteDoctor(doctor.id)">取消关注</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {addNotice, delNotice, getNotice, updateNotice} from "@/api/system/notice";
import {followRemove, listFollow} from "@/api/patient/patient";

export default {
  name: "Notice",
  dicts: ['hospital_department'],
  data() {
    return {
      doctorPic:'',
      doctorName:'',
      doctorPositions:'',
      doctorHospital:'',
      doctorDepartments:'',
      // 遮罩层
      loading: true,
      doctors:[],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeTitle: undefined,
        createBy: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [
          {required: true, message: "公告标题不能为空", trigger: "blur"}
        ],
        noticeType: [
          {required: true, message: "公告类型不能为空", trigger: "change"}
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    deleteDoctor(doctor) {
      console.log(doctor);
      followRemove(doctor).then(response => {
        this.getList();
        this.$modal.msgSuccess("取消关注成功");
      })
    },
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      listFollow().then(response => {
        console.log(response);
        this.doctors = response.data
        console.log(this.doctors);
        for (let i = 0; i < response.data.length; i++) {
          this.doctorPic = response.data[i].doctorPic;
          this.doctorName = response.data[i].doctorName;
          this.doctorPositions = response.data[i].doctorPositions;
          this.doctorHospital = response.data[i].doctorHospital;
          this.doctorDepartments = response.data[i].doctorDepartments;
        }
        this.noticeList = response.data;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加公告";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const noticeId = row.noticeId || this.ids
      getNotice(noticeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改公告";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.noticeId != undefined) {
            updateNotice(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNotice(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const noticeIds = row.noticeId || this.ids
      this.$modal.confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项？').then(function () {
        return delNotice(noticeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    }
  }
};
</script>
<style>
.vertical-table {
  display: flex;
  flex-direction: column;
  padding: 10px;
  border: 1px solid #ccc; /* 添加边框 */
  border-collapse: collapse; /* 合并边框 */
}

.table-row {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.table-cell {
  flex: 1;
  font-weight: bold;
  margin-right: 10px;
}

.table-cell:last-child {
  margin-right: 0;
}


.vertical-table {
  display: flex;
  flex-direction: column;
}

.data-block {
  margin-bottom: 20px;
}

.table-row {
  display: flex;
}

.table-cell {
  flex: 1;
}
</style>
